<!DOCTYPE html><html><head><title>Ext.util.KeyMap | Ext JS 4.0 Documentation</title><script type="text/javascript" src="../ext-all.js"></script><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../scrollbars.css" type="text/css"><link rel="stylesheet" href="../docs.css" type="text/css"><link id="styleCss" rel="stylesheet" href="../style.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script><link rel="stylesheet" href="../prettify.css" type="text/css"><!-- link(rel: 'stylesheet', href: req.baseURL + '/css/ext4.css', type: 'text/css')--><link rel="shortcut icon" type="image/ico" href="../favicon.ico"><!--[if IE]>
<style type="text/css">.head-band { display: none; }
.header { border: 0; top: 0; left: 0px; background: url(../header.gif) repeat-x; }
.doc-tab .members .member a.more { background-color: #efefef; }
</style><link rel="stylesheet" href="/new/css/ie.css" type="text/css"><![endif]-->
</head><body id="ext-body" class="iScroll"><div id="notice" class="notice">For up to date documentation and features, visit 
<a href="http://docs.sencha.com/ext-js/4-0">http://docs.sencha.com/ext-js/4-0</a></div><div class="wrapper"><div class="head-band"></div><div class="header"><h2><a href="../index.html">Sencha Documentation</a></h2></div><div id="search"><form><input type="text" placeholder="Search" id="search-field" autocomplete="off" name="q"></form><div id="search-box"></div></div><div id="treePanel"></div><div id="container"><script type="text/javascript">

    req = {
        liveURL: '.',
        standAloneMode: true,
        origDocClass: 'Ext.util.KeyMap',
        docClass: 'Ext.util.KeyMap',
        docReq: 'Ext.util.KeyMap',
        version: '4.0',
        baseURL: '.',
        baseDocURL: '.',
        baseProdURL: '.'
    };

    clsInfo = {};



</script>

<script type="text/javascript" src="../search.js"></script>
<!--script type="text/javascript" src="/new/javascripts/app/examples.js"></script-->
<script type="text/javascript" src="../class_tree.js"></script>
<script type="text/javascript" src="../class_doc.js"></script>
<script type="text/javascript">
    req.source = 'KeyMap.html#Ext-util.KeyMap';
    clsInfo = {"methods":["KeyMap","addBinding","destroy","disable","enable","isEnabled","on","setDisabled"],"cfgs":[],"properties":[],"events":[],"subclasses":[]};
    Ext.onReady(function() {
        Ext.create('Docs.classPanel');
    });
</script><div id="top-block" class="top-block"><h1 id="clsTitle" class="cls"><a href="../source/KeyMap.html#Ext-util.KeyMap" target="_blank">Ext.util.KeyMap</a></h1></div><div id="docContent"><div id="doc-overview-content"><div class="lft"><p>Handles mapping keys to actions for an element. One key map can be used for multiple actions.
The constructor accepts the same config object as defined by <a href="Ext.util.KeyMap.html#addBinding" rel="Ext.util.KeyMap#addBinding" class="docClass">addBinding</a>.
If you bind a callback function to a KeyMap, anytime the KeyMap handles an expected key
combination it will call the function with this signature (if the match is a multi-key
combination the callback will still be called only once): (String key, <a href="Ext.EventObject.html" rel="Ext.EventObject" class="docClass">Ext.EventObject</a> e)
A KeyMap can also handle a string representation of keys.<br />
Usage:</p>

<pre class="prettyprint"><code>// map one key by key code
var map = new Ext.util.KeyMap("my-element", {
    key: 13, // or Ext.EventObject.ENTER
    fn: myHandler,
    scope: myObject
});

// map multiple keys to one action by string
var map = new Ext.util.KeyMap("my-element", {
    key: "a\r\n\t",
    fn: myHandler,
    scope: myObject
});

// map multiple keys to multiple actions by strings and array of codes
var map = new Ext.util.KeyMap("my-element", [
    {
        key: [10,13],
        fn: function(){ alert("Return was pressed"); }
    }, {
        key: "abc",
        fn: function(){ alert('a, b or c was pressed'); }
    }, {
        key: "\t",
        ctrl:true,
        shift:true,
        fn: function(){ alert('Control + shift + tab was pressed.'); }
    }
]);
</code></pre>


<p><b>Note: A KeyMap starts enabled</b></p>
<div class="members"><div class="m-methods"><a name="methods"></a><div class="definedBy">Defined By</div><h3 class="mth p">Methods</h3><div id="method-KeyMap" class="member f ni"><a href="Ext.util.KeyMap.html#method-KeyMap" rel="method-KeyMap" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.KeyMap.html" class="definedIn docClass">Ext.util.KeyMap</a><br/><a href="../source/KeyMap.html#Ext-util.KeyMap-method-constructor" class="viewSource">view source</a></div><a name="KeyMap"></a><a name="method-KeyMap"></a><a href="Ext.util.KeyMap.html#" rel="method-KeyMap" class="cls expand">KeyMap</a>(
<span class="pre">Mixed el, Object binding, [String eventName]</span>)
 : void</div><div class="description"><div class="short"><p>&nbsp;</p></div><div class="long">
<h3 class="pa">Parameters</h3><ul><li><span class="pre">el</span> : Mixed<div class="sub-desc"><p>The element to bind to</p>
</div></li><li><span class="pre">binding</span> : Object<div class="sub-desc"><p>The binding (see <a href="Ext.util.KeyMap.html#addBinding" rel="Ext.util.KeyMap#addBinding" class="docClass">addBinding</a>)</p>
</div></li><li><span class="pre">eventName</span> : String<div class="sub-desc"><p>(optional) The event to bind to (defaults to "keydown")</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
</li></ul></div></div></div><div id="method-addBinding" class="member ni"><a href="Ext.util.KeyMap.html#method-addBinding" rel="method-addBinding" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.KeyMap.html" class="definedIn docClass">Ext.util.KeyMap</a><br/><a href="../source/KeyMap.html#Ext-util.KeyMap-method-addBinding" class="viewSource">view source</a></div><a name="addBinding"></a><a name="method-addBinding"></a><a href="Ext.util.KeyMap.html#" rel="method-addBinding" class="cls expand">addBinding</a>(
<span class="pre">Object/Array binding</span>)
 : void</div><div class="description"><div class="short">Add a new binding to this KeyMap. The following config object properties are supported:

Property            Type    ...</div><div class="long"><p>Add a new binding to this KeyMap. The following config object properties are supported:</p>

<pre>Property            Type             Description
----------          ---------------  ----------------------------------------------------------------------
key                 String/Array     A single keycode or an array of keycodes to handle
shift               Boolean          True to handle key only when shift is pressed, False to handle the key only when shift is not pressed (defaults to undefined)
ctrl                Boolean          True to handle key only when ctrl is pressed, False to handle the key only when ctrl is not pressed (defaults to undefined)
alt                 Boolean          True to handle key only when alt is pressed, False to handle the key only when alt is not pressed (defaults to undefined)
handler             Function         The function to call when KeyMap finds the expected key combination
fn                  Function         Alias of handler (for backwards-compatibility)
scope               Object           The scope of the callback function
defaultEventAction  String           A default action to apply to the event. Possible values are: stopEvent, stopPropagation, preventDefault. If no value is set no action is performed. 
</pre>


<p>Usage:</p>

<pre><code>// Create a KeyMap
var map = new Ext.util.KeyMap(document, {
    key: Ext.EventObject.ENTER,
    fn: handleKey,
    scope: this
});

//Add a new binding to the existing KeyMap later
map.addBinding({
    key: 'abc',
    shift: true,
    fn: handleKey,
    scope: this
});
</code></pre>

<h3 class="pa">Parameters</h3><ul><li><span class="pre">binding</span> : Object/Array<div class="sub-desc"><p>A single KeyMap config or an array of configs</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
</li></ul></div></div></div><div id="method-destroy" class="member ni"><a href="Ext.util.KeyMap.html#method-destroy" rel="method-destroy" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.KeyMap.html" class="definedIn docClass">Ext.util.KeyMap</a><br/><a href="../source/KeyMap.html#Ext-util.KeyMap-method-destroy" class="viewSource">view source</a></div><a name="destroy"></a><a name="method-destroy"></a><a href="Ext.util.KeyMap.html#" rel="method-destroy" class="cls expand">destroy</a>(
<span class="pre">Boolean removeEl</span>)
 : void</div><div class="description"><div class="short"><p>Destroys the KeyMap instance and removes all handlers.</p>
</div><div class="long"><p>Destroys the KeyMap instance and removes all handlers.</p>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">removeEl</span> : Boolean<div class="sub-desc"><p>True to also remove the attached element</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
</li></ul></div></div></div><div id="method-disable" class="member ni"><a href="Ext.util.KeyMap.html#method-disable" rel="method-disable" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.KeyMap.html" class="definedIn docClass">Ext.util.KeyMap</a><br/><a href="../source/KeyMap.html#Ext-util.KeyMap-method-disable" class="viewSource">view source</a></div><a name="disable"></a><a name="method-disable"></a><a href="Ext.util.KeyMap.html#" rel="method-disable" class="cls expand">disable</a> : void</div><div class="description"><div class="short"><p>Disable this KeyMap</p>
</div><div class="long"><p>Disable this KeyMap</p>
<h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
</li></ul></div></div></div><div id="method-enable" class="member ni"><a href="Ext.util.KeyMap.html#method-enable" rel="method-enable" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.KeyMap.html" class="definedIn docClass">Ext.util.KeyMap</a><br/><a href="../source/KeyMap.html#Ext-util.KeyMap-method-enable" class="viewSource">view source</a></div><a name="enable"></a><a name="method-enable"></a><a href="Ext.util.KeyMap.html#" rel="method-enable" class="cls expand">enable</a> : void</div><div class="description"><div class="short"><p>Enables this KeyMap</p>
</div><div class="long"><p>Enables this KeyMap</p>
<h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
</li></ul></div></div></div><div id="method-isEnabled" class="member ni"><a href="Ext.util.KeyMap.html#method-isEnabled" rel="method-isEnabled" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.KeyMap.html" class="definedIn docClass">Ext.util.KeyMap</a><br/><a href="../source/KeyMap.html#Ext-util.KeyMap-method-isEnabled" class="viewSource">view source</a></div><a name="isEnabled"></a><a name="method-isEnabled"></a><a href="Ext.util.KeyMap.html#" rel="method-isEnabled" class="cls expand">isEnabled</a> : Boolean</div><div class="description"><div class="short"><p>Returns true if this KeyMap is enabled</p>
</div><div class="long"><p>Returns true if this KeyMap is enabled</p>
<h3 class="pa">Returns</h3><ul><li><span class="pre">Boolean</span>&nbsp; &nbsp;
</li></ul></div></div></div><div id="method-on" class="member ni"><a href="Ext.util.KeyMap.html#method-on" rel="method-on" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.KeyMap.html" class="definedIn docClass">Ext.util.KeyMap</a><br/><a href="../source/KeyMap.html#Ext-util.KeyMap-method-on" class="viewSource">view source</a></div><a name="on"></a><a name="method-on"></a><a href="Ext.util.KeyMap.html#" rel="method-on" class="cls expand">on</a>(
<span class="pre">Number/Array/Object key, Function fn, [Object scope]</span>)
 : void</div><div class="description"><div class="short"><p>Shorthand for adding a single key listener</p>
</div><div class="long"><p>Shorthand for adding a single key listener</p>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">key</span> : Number/Array/Object<div class="sub-desc"><p>Either the numeric key code, array of key codes or an object with the
following options:
{key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}</p>
</div></li><li><span class="pre">fn</span> : Function<div class="sub-desc"><p>The function to call</p>
</div></li><li><span class="pre">scope</span> : Object<div class="sub-desc"><p>(optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the browser window.</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
</li></ul></div></div></div><div id="method-setDisabled" class="member ni"><a href="Ext.util.KeyMap.html#method-setDisabled" rel="method-setDisabled" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.KeyMap.html" class="definedIn docClass">Ext.util.KeyMap</a><br/><a href="../source/KeyMap.html#Ext-util.KeyMap-method-setDisabled" class="viewSource">view source</a></div><a name="setDisabled"></a><a name="method-setDisabled"></a><a href="Ext.util.KeyMap.html#" rel="method-setDisabled" class="cls expand">setDisabled</a>(
<span class="pre">Boolean disabled</span>)
 : void</div><div class="description"><div class="short"><p>Convenience function for setting disabled/enabled by boolean.</p>
</div><div class="long"><p>Convenience function for setting disabled/enabled by boolean.</p>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">disabled</span> : Boolean<div class="sub-desc">
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
</li></ul></div></div></div></div></div></div></div><div id="pageContent"></div></div></div></div></body></html>